package dao.daoImpl;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import dao.AdminDao;
import dao.BaseDao;
import entity.Admin;



public class AdminDaoimpl extends BaseDao  implements AdminDao {
	
		public  Admin selectOne(String name,String password) {
		String sql="select * from s_admin where name=? and password=?";
		Admin admin = new Admin();
		try {
			PreparedStatement prst= con.prepareStatement(sql);
			prst.setString(1, name);
			prst.setString(2, password);
			ResultSet res = prst.executeQuery();
			System.out.println(res);
			while(res.next()) {
				admin = new Admin();
				admin.setUseid(res.getInt("useid"));
				admin.setName(res.getString("name"));
				admin.setPassword(res.getString("password"));
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
        return admin;
   }

		@Override
		public int insert(Admin admin) {
			String sql="insert into s_admin values(?,?,?)";
			// TODO Auto-generated method stub
			try {
				PreparedStatement prst= con.prepareStatement(sql);
				prst.setInt(1, admin.getUseid());
				prst.setString(2, admin.getName());
				prst.setString(3, admin.getPassword());
				return prst.executeUpdate();
				
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			// TODO Auto-generated method stub
			return -1;
		}
}